package com.baizhi.action;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import com.baizhi.service.impl.UserServiceImpl;

public class UserAction {
	private String name;
	private String password;
	private  String password2;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getPassword2() {
		return password2;
	}
	public void setPassword2(String password2) {
		this.password2 = password2;
	}
	//登录
	public String login() {
		UserService us = new UserServiceImpl();
		User user = us.selectByName(name);
		System.out.println(user);
		if(user != null && user.getPassword().equals(password)) {
			return "success";
		}else {
			return "false";
		}
	}
	//注册
	public String regist(){
		UserService us = new UserServiceImpl();
		if (!password.equals("") && !password2.equals("") && !name.equals("") && password2.equals(password)){
			us.insert(new User(0, name, password));
		}else{
			return "false";
		}
		return "success";
	}
}
